# 开发时间 2023/6/16 14:55
import sys
from tkinter import *
import main.StartScreenBtnEnt


class HomeScreen:
    @property
    def getRoot(self):
        root = Tk()
        return root


    @staticmethod
    def home_start():
        hs = HomeScreen()
        root = hs.getRoot
        root.title('学生管理系统')
        # root.geometry('400x300')
        user_label1 = Label(root, text='用户名：')
        pwd_label2 = Label(root, text='密   码：')
        # sticky='w'，实现两个标签文本左对齐
        user_label1.grid(row=0, column=0, padx=10, pady=5, sticky='w')
        pwd_label2.grid(row=1, column=0, padx=10, pady=5, sticky='w')

        username_entry = Entry(root)
        pwd_entry = Entry(root, show='*')
        username_entry.grid(row=0, column=1, padx=10, pady=5)
        pwd_entry.grid(row=1, column=1, padx=10, pady=5)

        # 头像图片跨越两行
        photo = PhotoImage(file='images/1.png', width=50, height=50)
        Label(root, image=photo, relief='raised').grid(row=0, column=2, rowspan=2, padx=5, pady=5)

        loginBtn1 = Button(root, text='登录', width=5, height=1, activebackground='red',
                           command=lambda: main.StartScreenBtnEnt.login(f'{username_entry.get()}',
                                                                   f'{pwd_entry.get()}', root))  # 拉姆达函数方便传入参数
        # 登录按钮跨越3列
        loginBtn1.grid(row=2, column=0, columnspan=2, padx=5, pady=5)

        registerBtn1 = Button(root, text='注册', width=5, height=1, activebackground='red',
                              command=main.StartScreenBtnEnt.register)  # 拉姆达函数方便传入参数
        # 注册按钮跨越3列
        registerBtn1.grid(row=2, column=1, columnspan=2, padx=5, pady=5)

        def _quit():
            # 销毁root窗口
            root.destroy()
            sys.exit(0)
            # 在此处下方可以写入结束线程的语句，如果开启了多线程的话。
        root.protocol("WM_DELETE_WINDOW", _quit)
        root.mainloop()


if __name__ == '__main__':
    HomeScreen().home_start()
